function e(e, t, i) {
    return t in e ? Object.defineProperty(e, t, {
        value: i,
        enumerable: !0,
        configurable: !0,
        writable: !0
    }) : e[t] = i, e;
}

Object.defineProperty(exports, "__esModule", {
    value: !0
});

var t = function(e) {
    return e && e.__esModule ? e : {
        default: e
    };
}(require("../../utils/api2"));

exports.default = {
    addTo: function(i) {
        var n, s = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : "", a = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : {}, l = s ? s + ".$$link" : "$$link";
        i.setData((n = {}, e(n, l + ".menuShown", !1), e(n, l + ".menu", []), n)), Object.assign(i, {
            $$linkGetNavs: function() {
                return this.$$linkNavsPromise || (this.$$linkNavsPromise = t.default.site.nav.lists({
                    data: {
                        sid: a.sid
                    },
                    desc: "加载"
                })), this.$$linkNavsPromise;
            },
            $$linkShowMenu: function(t) {
                this.$$linkTempKey = t.currentTarget.dataset.key, this.$$linkTempType = t.currentTarget.dataset.type, 
                this.setData(e({}, l + ".menuShown", !0));
            },
            $$linkHideMenu: function() {
                this.setData(e({}, l + ".menuShown", !1));
            },
            $$linkAttach: function(e) {
                var t = this, i = e.currentTarget.dataset.index;
                0 === i ? this.$route("/pages/editor/link-page/link-page?sid=" + a.sid + "&key=" + this.$$linkTempKey) : 1 === i ? this.$route("/pages/editor/link-site/link-site?sid=" + a.sid + "&key=" + this.$$linkTempKey + "&type=" + this.$$linkTempType) : 2 === i ? this.__$$getapplist(a.sid).then(function(e) {
                    if (e.length) {
                        var i = e[0].appid;
                        t.$route("/pages/editor/link-app/link-app?sid=" + a.sid + "&appid=" + i + "&key=" + t.$$linkTempKey);
                    } else wx.showModal({
                        content: "暂无已发布独立小程序",
                        showCancel: !1,
                        confirmText: "我知道了"
                    });
                }) : this.$$linkDetach();
            },
            $$linkDetach: function(e) {
                this.$$onLinkSelect([], this.$$linkTempKey);
            },
            $$onLinkSelect: function(e, t) {
                console.log("已选中链接", e, t);
            },
            __$$getapplist: function(e) {
                return new Promise(function(i, n) {
                    t.default.site.miniapp.lists({
                        data: {
                            sid: e
                        }
                    }).then(function(e) {
                        var t = e.applists;
                        t = t.filter(function(e) {
                            return ![ "apply", "authornotcomplete" ].includes(e.status);
                        }), i(t || []);
                    });
                });
            }
        });
    }
};